//
//  GXWNavgationController.swift
//  swift3.0项目开始
//
//  Created by 龚昕炜 on 16/7/27.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

import UIKit

class GXWNavgationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationBar.isHidden = true
    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        /** 不是跟控制器就隐藏底部tabbar */
        if childViewControllers.count > 0 {
            /** 隐藏底部tabbar */
            viewController.hidesBottomBarWhenPushed = true
            
            /** 有值且转为GXWBaseViewController */
            if let vc = viewController as? GXWBaseViewController {
            
                var title = "返回"
                
                /** 是首页的下一个控制器 */
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                /** 返回按钮 */
                vc.navItem.leftBarButtonItem = UIBarButtonItem.init(title: title, target: self, action: #selector(popVc), isBack:true)
            }
        }
        super.pushViewController(viewController, animated: true)
    }
    
    /** 返回 */
    @objc func popVc() {
        popViewController(animated: true)
    }

}
